<?php

namespace Modules\Admin\Entities;

use \Spatie\Permission\Models\Permission as ParentPermission;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Arr;

class Permission extends ParentPermission
{
    use HasFactory;


    protected $table = 'sys_permissions';

    protected $appends = ['type_name'];

    protected $guard_name = 'admin';

    protected $fillable = [
    ];

    /**
     * @return mixed
     */
    public function getTypeNameAttribute()
    {
        return $this->attributes['type_name'] = Arr::get([1=>'按钮',2=>'菜单'],$this->type);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function child()
    {
        return $this->hasMany(Permission::class,'parent_id','id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function allChild()
    {
        return $this->child()->with('allChild');
    }




    protected static function newFactory()
    {
        return \Modules\Admin\Database\factories\PermissionFactory::new();
    }
}
